package com.car.slave.im.model.user;

import java.util.Map;

import org.json.JSONObject;

import com.car.slave.im.model.IMMessage;
import com.car.slave.im.util.IMTool;

import android.content.ContentValues;
import android.database.Cursor;

@SuppressWarnings("serial")
public class IMAudioMessage extends IMUserMessage {

	public static final String COLUMN_AUDIO_FILE_URL = "audioFileUrl";
	public static final String COLUMN_AUDIO_FILE_PATH = "audioFilePath";
	
	public String audioFileUrl;
	public String audioFilePath;
	
	public IMAudioMessage() {
		super();
	}

	/**
	 * 构造发送的消息.
	 * @param audioFileUrl
	 */
	public IMAudioMessage(String audioFilePath) {
		super(IMUserMessage.getAutoMessageid(), TYPE_VOICE, 0);
		this.audioFilePath = audioFilePath;
	}
	
	/**
	 * 构造接送的消息.
	 * @param messageId
	 * @param audioFileUrl
	 */
	public IMAudioMessage(String messageId, String audioFileUrl) {
		super(messageId, TYPE_VOICE, 1);
		this.audioFileUrl = audioFileUrl;
	}
	
	@Override
	public byte[] getSendBuffer() {
		Map<String, String> jsonMap = getJsonMap();
		jsonMap.put("content", audioFileUrl);
		return IMTool.getIoBuffer(IMMessage.CMD_USER_CHAT_MSG, new JSONObject(jsonMap).toString());
	}

	@Override
	public void cursorToMessage(Cursor cursor) {
		super.cursorToMessage(cursor);
		audioFileUrl = cursor.getString(cursor.getColumnIndex(COLUMN_AUDIO_FILE_URL));
		audioFilePath = cursor.getString(cursor.getColumnIndex(COLUMN_AUDIO_FILE_PATH));
	}
	
	@Override
	public ContentValues getContentValues() {
		ContentValues cv = super.getContentValues();
		cv.put(COLUMN_AUDIO_FILE_URL, audioFileUrl);
		cv.put(COLUMN_AUDIO_FILE_PATH, audioFilePath);
		return cv;
	}
}
